# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
脚本类，用来对组合好的参数进行循环执行，依次带入组合参数请求。可加入对响应结果断言） 
pip install requests_toolbelt  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import time

import requests
from requests_toolbelt import MultipartEncoder

from msydwork.config.config_hipac import c_url
from pycacho.cachobase.file_deal import get_file


headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            "Cookie": "JSESSIONID=5A68C3BA02CC28A3FC0484DBA83F855C"      # admint=8910b6bee8b2caa419ca29ab9afe5a0724d1ebf4; adminhostid=3
        }

# 1. 生成放款文件 application/x-www-form-urlencoded
def downLoad_loanFile(date,sys_code):
    print('---------放款文件下载开始---------')
    fc_url = c_url + '/boss/downloadFile?fileDate=' + date +'&fileType=PAY_&sysCode='+sys_code
    print(fc_url)
    req1 = requests.get(fc_url, headers=headers)
    print("接口响应信息：", req1.text)

# 2. 上传放款文件
def upload_loanFile(file_name,file):
    print('---------放款文件上传开始---------')
    fc_url = c_url + '/boss/uploadFile'
    m = MultipartEncoder(
        fields={'file':(file_name, get_file(file) )}
    )
    headers['Content-Type'] = m.content_type
    req1 = requests.post(fc_url,data=m, headers=headers)
    print("接口响应信息：", req1.text)

if __name__ == '__main__':
    file_path = 'E:\zenglingwei\项目信息\\13.海拍客\测试\\'
    file_model = 'upload.xls'
    file_name = 'uploads.xls'
    # 1.下载文件
    downLoad_loanFile('20200928','HIPAC')
    time.sleep(2)
    # 2. 生成excel文件
    time.sleep(2)
    # 3. 上传文件
   # upload_loanFile(file_name,file_path+file_name)
